###
#Processing Journalist List
###

library(plyr)
library(stargazer)

load('journalist.RData')

###
#Summary of Reporter/Election Characteristics (Reported in main text)
###

#Outlet Type
round(mean(ifelse(journalist$type.detailed=="Newspaper", 1, 0)),digits=2)
round(mean(ifelse(journalist$type.detailed=="TV", 1, 0)),digits=2)
round(mean(ifelse(journalist$type.detailed=="Radio", 1, 0)),digits=2)
round(mean(ifelse(journalist$type.detailed=="Other", 1, 0)),digits=2)

#Region
round(mean(ifelse(journalist$region=="South", 1, 0)),digits=2)
round(mean(ifelse(journalist$region=="West", 1, 0)),digits=2)
round(mean(ifelse(journalist$region=="North Central", 1, 0)),digits=2)
round(mean(ifelse(journalist$region=="Northeast", 1, 0)),digits=2)

#Story Production
round(mean(journalist$congressional.coverage,na.rm=TRUE),digits=1)

#Election Denying Race
round(mean(journalist$election.denial.cand,na.rm=TRUE),digits=2)

#Reporting Background
round(mean(journalist$total.topics,na.rm=TRUE),digits=1)
round(mean(journalist$only.politics.reporter,na.rm=TRUE),digits=2)
round(mean(journalist$mix.reporter,na.rm=TRUE),digits=2)

round(mean(journalist$arts.lifestyle.reporter,na.rm=TRUE),digits=2)
round(mean(journalist$sports.reporter,na.rm=TRUE),digits=2)

#Perceived Election Competitiveness
round(mean(ifelse(journalist$competitiveness < 3, 1, 0),na.rm=TRUE),digits=2)

#Appendix Table B1: Election Characteristic Variation by Candidate Feature
democracy.bycontext <- lm(democracy.top.issue ~ election.denial.cand,data=journalist)
coverage.bycontext <- lm(election.coverage ~ election.denial.cand,data=journalist)
competitiveness.bycontext <- lm(competitiveness ~ election.denial.cand,data=journalist)

stargazer(democracy.bycontext,coverage.bycontext,competitiveness.bycontext,covariate.labels=c("(Intercept)","Covering Election Denying Candidate"),dep.var.labels=c("Democracy Issue","Coverage Amount","Competitiveness"),star.cutoffs=c(0.05),notes.align='l',digits=2,title="Campaign Evaluations on Candidate Type",intercept.bottom=FALSE,type='text')

###
#Additional Reporter/Election Characteristics (Appendix Table A2)
###

#Age
median(journalist$age,na.rm=TRUE)

#Gender
round(mean(ifelse(journalist$gender=="Male", 1, 0),na.rm=TRUE),digits=2)#Share Male
round(mean(ifelse(journalist$gender=="Female", 1, 0),na.rm=TRUE),digits=2)#Share Female

#PID
round(mean(ifelse(journalist$pid=="Democrat", 1, 0),na.rm=TRUE),digits=2)#Share Democratic
round(mean(ifelse(journalist$pid=="Independent", 1, 0),na.rm=TRUE),digits=2)#Share Independent
round(mean(ifelse(journalist$pid=="Republican", 1, 0),na.rm=TRUE),digits=2)#Share Republican

#Race/Ethnicity
round(mean(ifelse(journalist$race=="White/Caucasian", 1, 0),na.rm=TRUE),digits=2)#Share White
round(mean(ifelse(journalist$race!="White/Caucasian", 1, 0),na.rm=TRUE),digits=2)#Share Non-White

#Education
round(mean(ifelse(journalist$education %in% c("4-year College Degree","Doctoral Degree","Professional Degree (JD, MD)","Masters Degree"), 1, 0),na.rm=TRUE),digits=2)#Share College Degree
round(mean(ifelse(!(journalist$education %in% c("4-year College Degree","Doctoral Degree","Professional Degree (JD, MD)","Masters Degree")), 1, 0),na.rm=TRUE),digits=2)#Share No College Degree

#Outlet Size
round(mean(ifelse(journalist$size=="1-10 employees", 1, 0),na.rm=TRUE),digits=2)
round(mean(ifelse(journalist$size=="11-50 employees", 1, 0),na.rm=TRUE),digits=2)
round(mean(ifelse(journalist$size=="51-100 employees", 1, 0),na.rm=TRUE),digits=2)
round(mean(ifelse(journalist$size=="101+ employees", 1, 0),na.rm=TRUE),digits=2)

#Rankings of Issue Importance in Campaign
issue.rankings <- journalist[,c('abortion.rank','guns.rank','economy.rank','foreign.rank','crime.rank','democracy.rank','healthcare.rank')]

issue.rankings$abortion.top3 <- ifelse(issue.rankings$abortion.rank <= 3, 1, 0)
issue.rankings$guns.top3 <- ifelse(issue.rankings$guns.rank <= 3, 1, 0)
issue.rankings$economy.top3 <- ifelse(issue.rankings$economy.rank <= 3, 1, 0)
issue.rankings$foreign.top3 <- ifelse(issue.rankings$foreign.rank <= 3, 1, 0)
issue.rankings$crime.top3 <- ifelse(issue.rankings$crime.rank <= 3, 1, 0)
issue.rankings$democracy.top3 <- ifelse(issue.rankings$democracy.rank <= 3, 1, 0)
issue.rankings$healthcare.top3 <- ifelse(issue.rankings$healthcare.rank <= 3, 1, 0)

issue.ratings <- apply(X=issue.rankings[8:14],MARGIN=2,FUN=mean,na.rm=TRUE)
issue.ratings <- issue.ratings[order(issue.ratings)]
issue.ratings

###
#Figure 2 - Assessments of Statements on Campaign Coverage
###

assessments <- journalist[,c('adversary.pre','equal.pre','threats.pre','justify.pre','trust.pre','agenda.pre')]
likert.summary <- apply(X=assessments,MARGIN=2,FUN=mean)
likert.summary.sd <- apply(X=assessments,MARGIN=2,FUN=sd)
likert.summary.sd <- likert.summary.sd/sqrt(dim(journalist)[1])
likert.summary <- cbind.data.frame(likert.summary,likert.summary.sd)
names(likert.summary) <- c('mean','sd')
likert.summary <- likert.summary[order(likert.summary$mean,decreasing=TRUE),]

likert.summary$labels <- c('Let Pols Explain','Identify Democracy Threats','Increase Election Trust','Offer Equal Coverage','Adversary to Pols','Set Agenda')
likert.summary$upper <- likert.summary$mean + 2*likert.summary$sd
likert.summary$lower <- likert.summary$mean - 2*likert.summary$sd

pdf(file='figure2.pdf',height=4,width=6)
par(mar=c(4.1,8.5,.5,.5))
plot(y=6:1,x=likert.summary$mean,pch=16,xlim=c(1,7),ylab='',yaxt='n',xlab="Agreement",cex=1.5)
axis(side=2,at=6:1,labels=c('Let Politicians
Explain their Views','Identify Threats
to Democracy','Increase Trust
in Elections','Give Every Side
Equal Coverage','Serve as Adversary
to Politicians','Set Political Agenda'),las=1)
segments(x0=likert.summary$lower,x1=likert.summary$upper,y0=6:1,lwd=2)
dev.off()

##
#Table 1: Value Trade-offs in Control Condition
##

round(mean(journalist$tradeoff_1[which(journalist$democracy==0)],na.rm=TRUE),digits=1)
round(mean(journalist$tradeoff_2[which(journalist$democracy==0)],na.rm=TRUE),digit=1)
round(mean(journalist$tradeoff_3[which(journalist$democracy==0)],na.rm=TRUE),digits=1)

##
#Information Source DVs in Control Condition
##

round(mean(journalist$directors[which(journalist$democracy==0)],na.rm=TRUE))#Rating for Election Communication Toolkit from Election Directors
round(mean(journalist$denial[which(journalist$democracy==0)],na.rm=TRUE))#Rating for list of election denier candidates

round(mean(journalist$rcp[which(journalist$democracy==0)],na.rm=TRUE))#Rating for Congressional Polling
round(mean(journalist$experteval[which(journalist$democracy==0)],na.rm=TRUE))#Rating for Qualitative Evaluation of Race

###
#Table 2: Roll Call Importance by Topic in Control Condition
##

round(mean(journalist$abortion[which(journalist$democracy==0)],na.rm=TRUE),digits=1)
round(mean(journalist$certify[which(journalist$democracy==0)],na.rm=TRUE),digits=1)
round(mean(journalist$electoral[which(journalist$democracy==0)],na.rm=TRUE),digits=1)
round(mean(journalist$gun[which(journalist$democracy==0)],na.rm=TRUE),digits=1)
round(mean(journalist$chips[which(journalist$democracy==0)],na.rm=TRUE),digits=1)
round(mean(journalist$postal[which(journalist$democracy==0)],na.rm=TRUE),digits=1)

###
#Table 3: Headline DVs in Control Condition
###

round(mean(journalist$headline4[which(journalist$democracy==0)],na.rm=TRUE),digits=1)
round(mean(journalist$headline1[which(journalist$democracy==0)],na.rm=TRUE),digits=1)
round(mean(journalist$headline5.original[which(journalist$democracy==0)],na.rm=TRUE),digits=1)
round(mean(journalist$headline3.original[which(journalist$democracy==0)],na.rm=TRUE),digits=1)
round(mean(journalist$headline2.original[which(journalist$democracy==0)],na.rm=TRUE),digits=1)

###
#Combined Outcome
###

#Table B2 - Outcomes in Control Group of Study
round(mean(journalist$issue.prominence[which(journalist$democracy==0)],na.rm=TRUE),digits=2)
round(mean(journalist$value.tradeoffs[which(journalist$democracy==0)],na.rm=TRUE),digits=2)
round(mean(journalist$information.source[which(journalist$democracy==0)],na.rm=TRUE),digits=2)
round(mean(journalist$headline.ratings[which(journalist$democracy==0)],na.rm=TRUE),digits=2)

round(sd(journalist$issue.prominence[which(journalist$democracy==0)],na.rm=TRUE),digits=2)
round(sd(journalist$value.tradeoffs[which(journalist$democracy==0)],na.rm=TRUE),digits=2)
round(sd(journalist$information.source[which(journalist$democracy==0)],na.rm=TRUE),digits=2)
round(sd(journalist$headline.ratings[which(journalist$democracy==0)],na.rm=TRUE),digits=2)

#Table B3 - Loadings for Combined Outcome Scale
round(prcomp(journalist[,c('value.tradeoffs','information.source','headline.ratings','issue.prominence')],center=TRUE,scale=TRUE)$rotation[,1],digits=2)

###
#Effects of Tip Sheet
###

journalist$headline.ratings.std <- journalist$headline.ratings/sd(journalist$headline.ratings)
journalist$value.tradeoffs.std <- journalist$value.tradeoffs/sd(journalist$value.tradeoffs)
journalist$information.source.std <- journalist$information.source/sd(journalist$information.source)
journalist$issue.prominence.std <- journalist$issue.prominence/sd(journalist$issue.prominence)

main.effect <- lm( combined.dv ~ democracy + pre.scale + democracy.top.issue + political.share + factor(type),data=journalist)
headline.effect <- lm(headline.ratings.std ~ democracy + democracy.top.issue + political.share + pre.scale + factor(type),data=journalist)
value.effect <- lm(value.tradeoffs.std ~ democracy + democracy.top.issue + political.share + pre.scale + factor(type),data=journalist)
source.effect <- lm(information.source.std ~ democracy + democracy.top.issue + political.share + pre.scale + factor(type),data=journalist)
prominence.effect <- lm(issue.prominence.std ~ democracy + democracy.top.issue + political.share + pre.scale + factor(type),data=journalist)

effects.row <- c(main.effect$coefficients[2],prominence.effect$coefficients[2],headline.effect$coefficients[2],value.effect$coefficients[2],source.effect$coefficients[2])
ses.row <- c(summary(main.effect)$coefficients[2,2],summary(prominence.effect)$coefficients[2,2],summary(headline.effect)$coefficients[2,2],summary(value.effect)$coefficients[2,2],summary(source.effect)$coefficients[2,2])

effect.frame <- cbind.data.frame(effects.row,ses.row)
effect.frame$lower <- effect.frame[,1] - 1.96*effect.frame[,2]
effect.frame$upper <- effect.frame[,1] + 1.96*effect.frame[,2]
effect.frame$names <- c('Index','Coverage','Importance','Values','Source')

pdf(file='figure3.pdf',height=6,width=6)
par(mar=c(4.5,6.25,.5,.5))
plot(y=5:1,x=effect.frame$effects.row,pch=16,yaxt='n',ylab='',ylim=c(.5,5.5),xlim=c(-.25,.62),cex=2,main="",cex.axis=1.2,xlab="Tip Sheet Effect (SD Units)",cex.lab=1.2)
segments(y0=5:1,x0=effect.frame$lower,x1=effect.frame$upper,lwd=3.5)
abline(v=0,lty=2,lwd=1.5)
abline(h=4.5,lwd=2)
axis(side=2,at=c(5,4,3,2,1),labels=c('Index','Roll Call
Importance','Coverage
Decisions','Value
Tradeoffs','Information
Sources'),las=1,cex.axis=1.2)
dev.off()

#Benchmarks to Differences by Other Covariates
reporter.diff <- lm(combined.dv ~ only.politics.reporter,data=journalist,subset=which(democracy==0))
partisan.diff <- lm(combined.dv ~ factor(pid),data=journalist,subset=which(democracy==0))

###
#Evaluations of Tip Sheet
###

useful.effect <- lm(useful ~ democracy,data=journalist)
novel.effect <- lm(novel ~ democracy,data=journalist)

#Appendix Table C1
stargazer(useful.effect,novel.effect,title="Effect of Tip Sheet on Evaluations",star.cutoffs=c(0.05),notes.align='l',digits=2,dep.var.labels=c("Useful","Novel"),covariate.labels="Democracy Frame Tip Sheet",type="text")

###
#Differences by Respondent Type
###

#Table C2 - Baseline Control Group Differences by Reporter Type
baseline.differences <- lm(combined.dv ~ factor(type),data=journalist,subset=which(democracy==0))
stargazer(baseline.differences,type="text",star.cutoffs=c(0.05),digits=2,covariate.labels=c("Radio/Digital","TV","Constant"))

#Table C3 - Tipsheet Effect Estimate by Reporter Type
treatment.heterogeneity <- lm( combined.dv ~ democracy*I(type=="Other") + democracy*I(type=="TV") + pre.scale + democracy.top.issue + political.share,data=journalist)
stargazer(treatment.heterogeneity,type="text",star.cutoffs=c(0.05),keep=c(1,2,3,7,8),covariate.labels=c("Tipsheet","Radio/Digital","Television","Tipsheet*Radio/Digital","Tipsheet*Television"),digits=2)

